package design.cglibProxy;

import org.springframework.cglib.proxy.Enhancer;

public class HelloProxyFactory {
    private static Enhancer enhancer = new Enhancer();

    static {
        // 继承被代理的目标
        enhancer.setSuperclass(HelloServiceImpl.class);
        // 设置拦截回调函数
        enhancer.setCallback(new HelloMethodInterceptor());
    }

    public static HelloService getHelloProxy() {
        // 生成代理对象
        return (HelloService) enhancer.create();
    }
}
